import request from '@/utils/request'
import { urlPrefix } from './config'
import { formatQuery } from './util'
import qs from 'qs'

export function getTalentList(query) {
  const queryString = qs.stringify(query)
  const url = `${urlPrefix}/talent?${queryString}`
  return request({
    url: url,
    method: 'get'
  })
}

export function getTalentSpecialList(page = 1, status, query) {
  let url = `${urlPrefix}/talent_special?page=${page}`
  if (query) {
    query = formatQuery(query)
    url += `&${query}`
  }
  return request({
    url: url,
    method: 'get',
    params: status
  })
}

export function createTalent(data) {
  return request({
    url: `${urlPrefix}/talent`,
    method: 'post',
    data
  })
}

export function updateTalent(data) {
  return request({
    url: `${urlPrefix}/talent/${data.id}`,
    method: 'patch',
    data
  })
}

export function deleteTalent(id) {
  return request({
    url: `${urlPrefix}/talent/${id}`,
    method: 'delete'
  })
}

export function sendWaiting(id, time, group) {
  const data = { interview_status: 1, time: time, group: group }
  return request({
    url: `${urlPrefix}/talent/send_waiting_interview/${id}`,
    method: 'patch',
    data
  })
}

export function sendWaiting2(id) {
  return request({
    url: `${urlPrefix}/talent/send_waiting_interview2/${id}`,
    method: 'patch'
  })
}

export function sendSecond(id, time, group) {
  const data = { interview_status: 6, time: time, group: group }
  return request({
    url: `${urlPrefix}/talent/send_second_interview/${id}`,
    method: 'patch',
    data
  })
}

export function sendHr(id, time, group) {
  const data = { interview_status: 10, time: time, group: group }
  return request({
    url: `${urlPrefix}/talent/send_hr_interview/${id}`,
    method: 'patch',
    data
  })
}

export function mulWaiting(data) {
  return request({
    url: `${urlPrefix}/talent/mul_waiting_interview`,
    method: 'post',
    data
  })
}

export function downloadTemplate() {
  return request({
    url: `${urlPrefix}/talent/download_template`,
    method: 'get'
  })
}
